package com.jse.util;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

@FunctionalInterface
public interface Invocation extends InvocationHandler {
	
	public default void before(Object target,Method method, Object[] args){
		
	}
	
	public default Object after(Object ret,Object target,Method method, Object[] args) {
		return ret;
	}
	public default Object error(Throwable e,Object target,Method method, Object[] args) {
		return null;
	}
	public Object get();
	
	@Deprecated
	public default Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		Object o=null;
		try {
			before(get(), method, args);
			o=method.invoke(get(),args);
		}catch(Throwable e) {
			return error(e, get(),method,args);
		}
		return after(o,get(),method,args);
	}
	
}
